package com.amsp.oa.oademo.service.impl;

import com.amsp.oa.oademo.entity.LuyongNotice;
import com.amsp.oa.oademo.mapper.LuyongNoticeMapper;
import com.amsp.oa.oademo.service.LuyongNoticeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class LuyongNoticeServiceImpl extends ServiceImpl<LuyongNoticeMapper, LuyongNotice>
        implements LuyongNoticeService {

    @Override
    public IPage<LuyongNotice> getPage(int current, int size, LuyongNotice notice) {
        LambdaQueryWrapper<LuyongNotice> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(LuyongNotice::getCreateTime);

        if (notice != null) {
            if (StringUtils.hasText(notice.getApplicantName())) {
                wrapper.like(LuyongNotice::getApplicantName, notice.getApplicantName());
            }
            if (StringUtils.hasText(notice.getDeptName())) {
                wrapper.like(LuyongNotice::getDeptName, notice.getDeptName());
            }
            if (StringUtils.hasText(notice.getPositionName())) {
                wrapper.like(LuyongNotice::getPositionName, notice.getPositionName());
            }
        }

        return page(new Page<>(current, size), wrapper);
    }
}